package com.voxel.sense.infomsg.module.map.warn;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;

import java.util.List;

import butterknife.BindView;
import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.response.FirmLatestOverDataEntity;
import cyy.example.com.facotry.model.api.response.WarningFirmEntity;
import cyy.example.com.facotry.share.SPEngine;

public class FirmWarnAdapter extends RecyclerAdapter<FirmLatestOverDataEntity> {

    interface OnItemClickListeners {
        void onClick(FirmLatestOverDataEntity data, int position);
    }
    public OnItemClickListeners lisn;

    public void setOnItemClickener(OnItemClickListeners listener){
        this.lisn = listener;
    }

    interface OnComponeClickener{
      void onComClick(FirmLatestOverDataEntity data);
    }
  public OnComponeClickener componeClickener;

  public void setOnComClickener(OnComponeClickener listener){
    this.componeClickener = listener;
  }


  private List<FirmLatestOverDataEntity> data;
    public void setData(List<FirmLatestOverDataEntity> warn){
        this.mDataList = warn;
        notifyDataSetChanged();
    }

    @Override
    protected int getItemViewType(int position, FirmLatestOverDataEntity conditionBean) {
        return R.layout.item_recycle_warm;
    }

    @Override
    protected ViewHolder<FirmLatestOverDataEntity> onCreateViewHolder(View root, int viewType) {
        return new FirmWarnAdapter.ViewHoder(root);
    }

     class ViewHoder extends ViewHolder<FirmLatestOverDataEntity> {
        @BindView(R.id.compute_name)
        TextView computeName;
        @BindView(R.id.go_task)
        Button goTask;
        @BindView(R.id.over_tip)
        TextView mOverTip;
        public ViewHoder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(FirmLatestOverDataEntity bean) {


            computeName.setText(bean.getCompanyName());
            if(bean.getOverData() == 1){
                mOverTip.setText("异常");
            }else{
                mOverTip.setText("超标");
            }
            computeName.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                if(componeClickener != null){
                  componeClickener.onComClick(bean);
                }
              }
            });
            String distributing = SPEngine.getSPEngine().getUserInfo().getDistributing();
            if (Constants.NO_TASK_DISPATCH_PERMI.equals(distributing)) {
                goTask.setEnabled(false);
                goTask.setBackground(goTask.getContext().getDrawable(R.drawable.sp_btn_task_uncheck));
            } else {
                goTask.setEnabled(true);
                goTask.setBackground(goTask.getContext().getDrawable(R.drawable.sp_btn_task));

            }
            goTask.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if(lisn != null){
                        lisn.onClick(bean, getLayoutPosition());
                    }
                }
            });
        }
    }




}

